package com.example.demo.blog;

import com.example.demo.model.Article;
import com.example.demo.model.CommonResponse;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * Created by 豆腐干Sama on 2018/3/2.
 */
@Controller
public class ArticleController {
    @Autowired
    private ArticleService articleService;
    @GetMapping("api/articles")
    @ResponseBody
    public PageInfo<Article> articles(@RequestParam("pageNo") int pageNo) {
        PageInfo<Article> articles = articleService.articles(pageNo);
        return articles;
    }
    @GetMapping("api/articles/detail/{id}")
    @ResponseBody
    public Article article(@PathVariable int id) {
        Article article = articleService.get(id);
        return article;
    }
    @PostMapping("api/articles/save")
    @ResponseBody
    public CommonResponse save(@RequestBody Article article) {
        CommonResponse response = new CommonResponse();
        article.setCreateTime(new Date());
        articleService.insert(article);
        response.succeed(null);
        return response;
    }
    @GetMapping("index")
    public String index() {
        System.out.println("进入index");
        return "index";
    }
    @GetMapping("index2")
    public String index2() {
        return "index2";
    }


}
